package ${webPackageName}.controller.sys;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import ${commonPackageName}.annotation.Permission;
import ${commonPackageName}.annotation.RequestLog;
import ${servicePackageName}.entity.sys.SysRole;
import ${servicePackageName}.qo.other.BatchDeleteQo;
import ${servicePackageName}.qo.sys.ResoucesAuthorizationReq;
import ${servicePackageName}.qo.sys.RoleListPageReq;
import ${servicePackageName}.qo.sys.RoleReq;
import ${servicePackageName}.service.sys.ISysRoleService;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 角色相关接口
 * </p>
 *
 * @author lizihao
 * @since 2020-11-18
 */
<#noparse>
@Api(tags = {"角色相关接口"})
@RestController
@RequestMapping("/base/sysRole")
public class SysRoleController{

	@Autowired
	private ISysRoleService iSysRoleService;
	
	@ApiOperation(value = "新增或修改角色")
	@Permission
	@RequestLog
    @RequestMapping(value = "/addOrUpdate", method = RequestMethod.POST)
	public Boolean add(@Validated @RequestBody RoleReq userReq) throws Exception{
		iSysRoleService.saveOrUpdateUser(userReq);
	 return true;
 }
	
	@ApiOperation(value = "删除角色")
	@Permission
	@RequestLog
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
	public Boolean delete(@RequestBody BatchDeleteQo batchDeleteQo) throws Exception{
		iSysRoleService.delete(batchDeleteQo);
	 return true;
 }
	
	@ApiOperation(value = "角色信息")
	@Permission
	@RequestLog
    @RequestMapping(value = "/info", method = RequestMethod.POST)
	public SysRole info(@RequestParam("id") Long id) throws Exception{
	 return iSysRoleService.getById(id);
 }
	
	@ApiOperation(value = "角色列表")
	@Permission
	@RequestLog
    @RequestMapping(value = "/page", method = RequestMethod.POST)
	public IPage<SysRole> page(@RequestBody RoleListPageReq pageReq) throws Exception{
		QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("is_delete", 0);
		queryWrapper.eq(null != pageReq.getIsEnable(), "is_enable", pageReq.getIsEnable());
		queryWrapper.like(StrUtil.isNotBlank(pageReq.getRoleName()),"role_name", pageReq.getRoleName());
		queryWrapper.like(StrUtil.isNotBlank(pageReq.getRoleCode()),"role_code", pageReq.getRoleCode());
	 return iSysRoleService.page(pageReq.getPage(), queryWrapper);
 }
	
	@ApiOperation(value = "角色列表(所有)")
	@Permission
	@RequestLog
    @RequestMapping(value = "/pageAll", method = RequestMethod.POST)
	public List<SysRole> pageAll() throws Exception{
	 return iSysRoleService.list();
 }
	
	@ApiOperation(value = "角色菜单授权")
	@Permission
	@RequestLog
    @RequestMapping(value = "/resoucesAuthorization", method = RequestMethod.POST)
	public Boolean resoucesAuthorization(@Validated @RequestBody ResoucesAuthorizationReq resoucesAuthorizationReq) throws Exception{
		iSysRoleService.resoucesAuthorization(resoucesAuthorizationReq);
	 return true;
 }
}
</#noparse>